package org.six11.ss.client;

import java.util.Map;

import org.six11.ss.shared.Message;
import org.six11.util.adt.MultiState;

/**
 * 
 * 
 * @author Gabe Johnson <johnsogg@cmu.edu>
 */
public class LeaveRoomMessageHandler extends AWTMessageHandler {

  /**
   * @param state
   */
  protected LeaveRoomMessageHandler(MultiState state) {
    super(state);
  }

  /**
   * 
   */
  @Override
  public void handleAWT(Message msg) {
    String who = msg.getParam("personNick");
    String room = msg.getParam("roomName");
    String reason = msg.getParam("reason");
    String why = reason == null ? "" : " (" + reason + ")";
    TextConsole text = getConsole();

    text.addStatus(who + " has left " + room + why);

    String whoID = msg.getParam("personID");
    if (whoID.equals(state.getString(ClientStateNames.K_MY_ID))) {
      Map<String, CommandHandler> handlers = (Map<String, CommandHandler>) state
          .getValue(ClientStateNames.K_COMMAND_HANDLERS);
      handlers.get("list").handleCommand("");
    }

  }

}
